/*
 * =====================================================================================
 *       Filename:  read_command.c
 *    Description:  
 *        Version:  1.0
 *        Created:  2017.05.25 23:54
 *         Author:  fujiajun (fjj), fujiajun@renren1.com
 *        Company:  HOOLINKS
 * =====================================================================================
 */

#include "xshell.h"

void read_command(struct Command* command){
    char str[INPUTMAX];
    char *delims = " ";
    char *result = NULL;
    int length;
    int i;
    char pathname[MAXPATHLEN];

    // 读入命令字符串
    fgets(str, INPUTMAX, stdin);
    length = strlen(str) - 1;
    str[length] = '\0';


    // 获取当前路径
    getcwd(pathname, MAXPATHLEN);
    command->path = pathname;

    
    // 构造命令结构体
    i = -1;
    result = strtok(str, delims);
    while(result != NULL && i < PARAMNUM) {
        if(i == -1){
            command->command = result;
        } else{
            command->param[i] = result;
        }
        
        result = strtok(NULL, delims);
        i++;
    }
    command->paramNum = i;

}